package csc.daonjpa.java.serviceimpl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import csc.daonjpa.java.beans.AccountBean;
import csc.daonjpa.java.dao.AccountDAO;
import csc.daonjpa.java.domain.Account;
import csc.daonjpa.java.service.AccountService;

@Service
public class AccountServiceImpl implements AccountService {

	public AccountDAO getAccountDao() {
		return accountDao;
	}

	public void setAccountDao(AccountDAO accountDao) {
		this.accountDao = accountDao;
	}

	@Autowired
	AccountDAO accountDao;
	
	@Override
	public List<AccountBean> getAccountList() {
		List<Account> accounts = accountDao.getAccounts();
		List<AccountBean> accountBeans = new ArrayList<AccountBean>();
		
		for (Account account : accounts) {
			AccountBean accountBean = new AccountBean();
			accountBean.setAccountName(account.getAccountName());
			accountBean.setAccountType(account.getAccountType());
			accountBean.setId(account.getId());
			accountBean.setAvailableAmount(account.getAvailableAmount());
			
			accountBeans.add(accountBean);
		}
		
		return accountBeans;
	}

}
